﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="mtategevusalad_tegevusala", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MtategevusaladTegevusala))]
    public class MtategevusaladTegevusalaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMtategevusaladTegevusala clazz;
        
        public MtategevusaladTegevusalaSerializer(IMtategevusaladTegevusala clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tegevusala_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.TegevusalaId))).ToString());
            Writer.WriteEndElement();
            if (clazz.Ark!=null) {
                Writer.WriteStartElement("ark");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Ark))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EmtakKood!=null) {
                Writer.WriteStartElement("emtak_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.EmtakKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EmtakVersioon!=null) {
                Writer.WriteStartElement("emtak_versioon");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.EmtakVersioon))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Pohiteg!=null) {
                Writer.WriteStartElement("pohiteg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Pohiteg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKpv!=null) {
                Writer.WriteStartElement("algus_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.AlgusKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKpv!=null) {
                Writer.WriteStartElement("lopp_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.LoppKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Allikas!=null) {
                Writer.WriteStartElement("allikas");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Allikas))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AllikaKpv!=null) {
                Writer.WriteStartElement("allika_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.AllikaKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Muutus!=null) {
                Writer.WriteStartElement("muutus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Muutus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Mkuup!=null) {
                Writer.WriteStartElement("mkuup");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Mkuup))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tegevusala_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>tegevusala_id");
                }
                clazz.TegevusalaId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("tegevusala_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtategevusalad_tegevusala>tegevusala_id", Reader.LocalName);
            }
            if (Reader.LocalName=="ark") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>ark");
                }
                clazz.Ark = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ark")).Value;
            }
            if (Reader.LocalName=="emtak_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>emtak_kood");
                }
                clazz.EmtakKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("emtak_kood")).Value;
            }
            if (Reader.LocalName=="emtak_versioon") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>emtak_versioon");
                }
                clazz.EmtakVersioon = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("emtak_versioon")).Value;
            }
            if (Reader.LocalName=="pohiteg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>pohiteg");
                }
                clazz.Pohiteg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("pohiteg")).Value;
            }
            if (Reader.LocalName=="algus_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>algus_kpv");
                }
                clazz.AlgusKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("algus_kpv")).Value;
            }
            if (Reader.LocalName=="lopp_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>lopp_kpv");
                }
                clazz.LoppKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("lopp_kpv")).Value;
            }
            if (Reader.LocalName=="allikas") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>allikas");
                }
                clazz.Allikas = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("allikas")).Value;
            }
            if (Reader.LocalName=="allika_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>allika_kpv");
                }
                clazz.AllikaKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("allika_kpv")).Value;
            }
            if (Reader.LocalName=="muutus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>muutus");
                }
                clazz.Muutus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("muutus")).Value;
            }
            if (Reader.LocalName=="mkuup") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtategevusalad_tegevusala>mkuup");
                }
                clazz.Mkuup = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("mkuup")).Value;
            }
        }
    }
}
